import requests
from bs4 import BeautifulSoup

# 目标 URL
url = "https://www.mi.com/shop/comment/20580.html"

# 伪装请求头，模拟浏览器访问
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
    "Referer": "https://www.mi.com/"
}

# 发送请求
response = requests.get(url, headers=headers)

# 判断请求是否成功
if response.status_code == 200:
    soup = BeautifulSoup(response.text, "html.parser")

    # 查找评论数据（可能需要调整 class 名）
    comments = soup.find_all("div", class_="comment-content")  # 需要检查网页的实际 class 名称

    # 输出评论
    for idx, comment in enumerate(comments, 1):
        print(f"评论 {idx}: {comment.text.strip()}")

else:
    print(f"请求失败，状态码: {response.status_code}")